/**
 *
 */
moduleMain.controller("DashboardLearningMapAnswerCourseInfo", function ($scope, $log, $state, $stateParams, DashboardLearningMapAnswerInfoResource, LoadingService, ConstantService, DialogService, $$CambioConfig) {
    initPage($scope);
    $scope.$on("$viewContentLoaded", function () {
        $scope.reset();
        pageOnLoad($scope);
        $scope.currentState = $state.current;
        if ($scope.currentState.name === $state.current) {
            ConstantService.addState($state.current, true);
        }

        $scope.user = ConstantService.getItem('user');
        if ($stateParams.organizationClientId) {
            $scope.currentOrganizationClientId = $stateParams.organizationClientId;
        } else {
            $scope.currentOrganizationClientId = $scope.user.createOrgId;
        }

        $scope.queryPara = JSON.parse(Base64.decode(decodeURIComponent($stateParams.query)));
        if ($scope.queryPara.courseId) {
            $scope.queryPara.current = true;
        } else {
            $scope.queryPara.current = false;
        }
        $scope.query(1);
        // $scope.async();
    });

    $scope.reset = function () {

    }

    $scope.onQueryKeyDown = function () {
        if (event.keyCode == 13) {
            $scope.query(1);
        }
    }

    $scope.query = function (pageNo) {
        DashboardLearningMapAnswerInfoResource.answerInfo({pageNo: pageNo - 1, pageSize: 10, current: $scope.queryPara.current, organizationClientId: $scope.currentOrganizationClientId}, $scope.queryPara, function (queryResult) {
            $log.debug("查询结果", queryResult.data);
            $scope.queryResult = queryResult.data;
            $scope.pagination.setPage(queryResult.data, pageNo);
            //LoadingService.hide();
        });
    };
    $scope.pagination = new Pagination();
    $scope.pagination.setPageClickFn($scope.query);

    $scope.export = function () {

        DashboardLearningMapAnswerInfoResource.exportExcel({current: $scope.queryPara.current, organizationClientId: $scope.currentOrganizationClientId}, $scope.queryPara, function (queryResult) {
            $log.debug("查询结果", queryResult.data);
            window.open($$CambioConfig.EXCEL_FILE_URL.format({uuid: queryResult.data.value}), '_blank');
        });
    }

    $scope.async = function () {
        DashboardLearningMapAnswerInfoResource.async({current: $scope.queryPara.current, organizationClientId: $scope.currentOrganizationClientId}, $scope.queryPara, function (queryResult) {
            $log.debug("查询结果", queryResult.data);
            Alert.success('正在同步，时间会比较长，请耐心等待');
        });
    }

    function addCurrentRow(row) {
        var sbHtml = new StringBuffer();
        sbHtml.append('<tr>');
        sbHtml.append('<td>' + row.nickName + '</td>');
        sbHtml.append('<td>' + row.employeeId + '</td>');
        sbHtml.append('<td>' + row.startTime.toDateTime() + '</td>');
        sbHtml.append('<td>' + row.endTime.toDateTime() + '</td>');
        sbHtml.append('<td>' + row.companyName + '</td>');
        sbHtml.append('<td>' + row.status + '</td>');
        sbHtml.append('</tr>');
        $("#reportData tr:last-child").after(sbHtml.toString());
    }
});